package com.distribute.framework.core.lsf;

import java.util.HashSet;
import java.util.Set;

import com.distribute.framework.core.lsf.entity.AppInfo;
import com.distribute.framework.core.lsf.protocol.ILsfManager;
import com.distribute.framework.core.sql.redis.RedisSupport;

public class LsfRedisManager implements ILsfManager {
	
	private Lsf lsf=null;
	private RedisSupport redisSupport = null;
	
	/**
	 * @param lsf
	 */
	public LsfRedisManager(Lsf lsf) {
		super();
		this.lsf = lsf;
		redisSupport = RedisSupport.getRedis(lsf.getRedis());
	}

	/**
	 * 登录,同时拉取服务列表
	 * @return
	 */
	public Set<AppInfo> login() {
		Set<AppInfo> set = new HashSet();
		Set<String> keys = redisSupport.getMapKeys("LSF."+lsf.getFlag());
		for(String key:keys){
			set.add((AppInfo)redisSupport.getMap("LSF."+lsf.getFlag(), key));
		}
		return set;
	}
	
	/**
	 * 注册服务
	 * @param serverInfo
	 */
	public Boolean regist(AppInfo serverInfo) {
		redisSupport.setMap("LSF."+lsf.getFlag(), serverInfo.getUrl(), serverInfo);
		return true;
	}

	public Lsf getLsf() {
		return lsf;
	}

	public void setLsf(Lsf lsf) {
		this.lsf = lsf;
	}
}